home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr11 / powerb5.zip / P5SPR004.TIP < prev    next >
Text File  |  1993-06-01  |  2KB  |  58 lines

  1. Occasionally I need to write a 1-2-3 macro that loops
  2. through a list of items in a worksheet. For instance, if I'm
  3. printing mailing labels from a list of clients, I might want
  4. to move each address in turn to a "scratch" area, format it,
  5. then send it along to the printer. The lists are often very
  6. long, so it doesn't pay to write a line of code for each of
  7. them.
  8.  
  9. In this example, a looping macro that starts in cell C3
  10. copies the first name in the A3..A7 range to A20, prints the
  11. name, then repeats the process with the next name down until
  12. the bottom of the list; there are only five names in this
  13. example, but the macro as written handles up to 300.
  14.  
  15.    A       B        C        D        E        F     G
  16.  
  17. 1  LIST         MACRO TO SEQUENTIALLY COPY ELEMENTS OF A LIST
  18. 2
  19. 3  Jan     \P       {LET G13,0}~                        sets LOOPCOUNT to 0
  20. 4  Richie           /CA9~A20~                           copies one list element to target
  21. 5  Ed               /PPRA20..A20~GQ                     prints each list element
  22. 6  Paula            {LET G13,G13+1}~                    increments LOOPCOUNTER
  23. 7  Anna             {IF @COUNT(A3..A300)<=G13}{QUIT}    QUITs loop at end of list
  24. 8                   {BRANCH C4}~                        loops back to start
  25. 9
  26. 10
  27. 11
  28. 12         LIST OF MACRO TEXT SEGMENTS                  LOOPCOUNTER
  29. 13         /CA                                           6  # of loop executions
  30. 14         A20                                          9   row # referenced by MACRO (C4)
  31. 15         ~
  32.  
  33.  
  34. I use 1-2-3's text concatenation operator (represented by an
  35. ampersand) to create a reference to a new cell address each
  36. time the loop cycles. The formula in cell C4 creates a
  37. concatenated text string from segments in B13..B15 and a
  38. loop counter in G14. Each time the loop executes, the string
  39. in C4 changes. The iteration count is displayed in cell G13
  40. and converted to a string in G14 via the @STRING() function.
  41.  
  42. Rick Brown
  43. Marietta, Ohio
  44.  
  45. Editor's Note: Mr. Brown's sample worksheet is included in
  46. the file P5SPR\LOOP.WK1 on your PowerBase *.* Volume 5
  47. diskette. Note that C3, the cell where the macro starts
  48. running, has the label \P -- to which 1-2-3 automatically
  49. branches when <Alt>-P is pressed.
  50.  
  51.  
  52. Title: Looping in Lotus
  53. Category: SPR
  54. Issue Date: June, 1992
  55. Editor: Brett Glass
  56. Supplementary Files: P5SPR\LOOP.WK1
  57. Filename: P5SPR004.TIP
  58.